import request from '@/utils/request'

// 查询区域管理列表
export function listRegion(query) {
  return request({
    url: '/manage/region/list',
    method: 'get',
    params: query
  })
}

// 查询区域管理详细
export function getRegion(id) {
  return request({
    url: '/manage/region/' + id,
    method: 'get'
  })
}

// 新增区域管理
export function addRegion(data) {
  return request({
    url: '/manage/region',
    method: 'post',
    data: data
  })
}

// 修改区域管理
export function updateRegion(data) {
  return request({
    url: '/manage/region',
    method: 'put',
    data: data
  })
}

// 删除区域管理
export function delRegion(id) {
  return request({
    url: '/manage/region/' + id,
    method: 'delete'
  })
}

// 获取区域树结构数据
export function getRegionTreeData(query) {
  return request({
    url: '/manage/region/treeData',
    method: 'get',
    params: query
  })
}

// 获取区域下拉树结构数据
export function getRegionTreeSelect(query) {
  return request({
    url: '/manage/region/treeselect',
    method: 'get',
    params: query
  })
}

// 获取区域统计信息
export function getRegionStatistics(regionId) {
  // 如果regionId为null或undefined，则使用all路径
  if (regionId === null || regionId === undefined) {
    return request({
      url: '/manage/region/statistics/all',
      method: 'get'
    })
  }
  return request({
    url: '/manage/region/statistics/' + regionId,
    method: 'get'
  })
}

// 检查区域层级限制
export function checkRegionLevel(regionId, maxLevel = 5) {
  return request({
    url: '/manage/region/checkLevel',
    method: 'get',
    params: {
      regionId: regionId,
      maxLevel: maxLevel
    }
  })
}
